package cn.houserent.service.impl;

import java.util.List;

import org.hibernate.Transaction;

import cn.houserent.dao.HibernateUtil;
import cn.houserent.dao.HouseDao;
import cn.houserent.dao.impl.HouseDaoImpl;
import cn.houserent.entity.House;
import cn.houserent.service.HouseBiz;

public class HouseBizImpl implements HouseBiz{
	private HouseDao houseDao = new HouseDaoImpl(); 

	@Override
	public List<House> getHouseList(House house, int pageNo, int pageSize) {
		Transaction tx =null;
		List<House> list = null;
		try{
			tx = HibernateUtil.currentSession().beginTransaction();
			list = houseDao.getList(house, pageNo, pageSize);
			tx.commit();
		}catch (Exception e) {
			e.printStackTrace();
			if(tx != null){
				tx.rollback();
			}
		}
		return list;
	}

	@Override
	public int getCount(House house) {
		Transaction tx =null;
		Integer count = null;
		try{
			tx = HibernateUtil.currentSession().beginTransaction();
			count = Integer.parseInt(houseDao.countHouse(house).toString());
			tx.commit();
		}catch (Exception e) {
			e.printStackTrace();
			if(tx != null){
				tx.rollback();
			}
		}
		return count;
	}

}
